<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="entjava.poker.model.*"  
    import="java.util.*"%>
     <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Success JSP</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css">  
<script type="text/javascript"  language="javascript" src="jrefresh.js"></script> 
</head>
<body id="theBody" onload="fixBrokenImages()">
<% ArrayList<Player> al = (ArrayList<Player>)request.getServletContext().getAttribute("pList");%> 
 <% Game game= (Game)request.getServletContext().getAttribute("game"); %>
 
<h5>Login Successful!</h5>  Hello  ${player.name}

<div id= theContainer>
<div id="Player0"><center>
Player: ${sessionScope.playservice.players[0].name}<br>				
Money:${sessionScope.playservice.players[0].money}<br>
Bet:${sessionScope.playservice.players[0].bet}<br>
																	<%--if round 4 has all checked show this player's cards --%>
<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==4}'>
    		<c:if test='${pList[0].isHasFolded()!=true  && pList.size() >=3 }'>
				<img src="${pList[0].hand.cardList[0].path}">
				<img src="${pList[0].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
	
</center></div>

<div id="Player1"><center>
Player: ${sessionScope.playservice.players[1].name}<br>
Money:${sessionScope.playservice.players[1].money}<br>
Bet:${sessionScope.playservice.players[1].bet}<br>

<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==4}'>
    		<c:if test='${pList[1].isHasFolded()!=true  && pList.size() >=3 }'>
				<img src="${pList[1].hand.cardList[0].path}">
				<img src="${pList[1].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
</center></div>

<div id="Player2"><center>
Player: ${sessionScope.playservice.players[2].name}<br>
Money:${sessionScope.playservice.players[2].money}<br>
Bet:${sessionScope.playservice.players[2].bet}<br>

<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==4}'>
    		<c:if test='${pList[2].isHasFolded()!=true  && pList.size() >=3 }'>
				<img src="${pList[2].hand.cardList[0].path}">
				<img src="${pList[2].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
</center></div>

<div id="Player3"><center>
Player: ${sessionScope.playservice.players[3].name}<br>
Money:${sessionScope.playservice.players[3].money}<br>
Bet:${sessionScope.playservice.players[3].bet}<br>

<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==4}'>
    		<c:if test='${pList[3].isHasFolded()!=true  && pList.size() >=4 }'>
				<img src="${pList[3].hand.cardList[0].path}">
				<img src="${pList[3].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
</center></div>

<div id="Middle"><center>
<%if(game!=null){						
	int pot=game.getPot();	
	out.print("The money in the Pot: "+pot );
	} %>			<%--try to use c if game exist, then show money in pot --%>
<br>
<%if(game!=null){	
	if(game.isNotOver()==false){
		String winner=""; String combo="";
		for(int i =0; i<al.size(); i++){		
			if(al.get(i).isWinner()){
				winner = al.get(i).getName();	
				combo = al.get(i).getHand().getCom();
			}
		}		
		out.print("The winner is "+ winner+" " +combo);
	}
}%>
<br>
<c:choose>
	<c:when test='${game!=null && game.getCountRounds()==1}'>
		<img src="${sessionScope.player.hand.cardList[2].path}">
		<img src="${sessionScope.player.hand.cardList[3].path}">
		<img src="${sessionScope.player.hand.cardList[4].path}">
	</c:when>
	
	<c:when test='${game!=null && game.getCountRounds()==2}'>
		<img src="${sessionScope.player.hand.cardList[2].path}">
		<img src="${sessionScope.player.hand.cardList[3].path}">
		<img src="${sessionScope.player.hand.cardList[4].path}">
		<img src="${sessionScope.player.hand.cardList[5].path}">
	</c:when>
	
	<c:when test='${game!=null && game.getCountRounds()>=3}'>
			<img src="${sessionScope.player.hand.cardList[2].path}">
			<img src="${sessionScope.player.hand.cardList[3].path}">
			<img src="${sessionScope.player.hand.cardList[4].path}">
			<img src="${sessionScope.player.hand.cardList[5].path}">
			<img src="${sessionScope.player.hand.cardList[6].path}">
	</c:when>
</c:choose>
</center></div>

<div id="Player4"><center>
Player: ${sessionScope.playservice.players[4].name}<br>
Money:${sessionScope.playservice.players[4].money}<br>
Bet:${sessionScope.playservice.players[4].bet}<br>

<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==4}'>
    		<c:if test='${pList[4].isHasFolded()!=true  && pList.size() >=5 }'>
				<img src="${pList[4].hand.cardList[0].path}">
				<img src="${pList[4].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
</center></div>

<div id="Player8"><center>
Player: ${sessionScope.playservice.players[8].name}<br>
Money:${sessionScope.playservice.players[8].money}<br>
Bet:${sessionScope.playservice.players[8].bet}<br>

<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==4}'>
    		<c:if test='${pList[8].isHasFolded()!=true  && pList.size() >=9 }'>
				<img src="${pList[8].hand.cardList[0].path}">
				<img src="${pList[8].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
</center></div>

<div id="Player7"><center>
Player: ${sessionScope.playservice.players[7].name}<br>
Money:${sessionScope.playservice.players[7].money}<br>
Bet:${sessionScope.playservice.players[7].bet}<br>

<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==4}'>
    		<c:if test='${pList[7].isHasFolded()!=true  && pList.size() >=4 }'>
				<img src="${pList[7].hand.cardList[0].path}">
				<img src="${pList[7].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
</center></div>

<div id="Player6"><center>
Player: ${sessionScope.playservice.players[6].name}<br>
Money:${sessionScope.playservice.players[6].money}<br>
Bet:${sessionScope.playservice.players[6].bet}<br>

<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==7}'>
    		<c:if test='${pList[6].isHasFolded()!=true  && pList.size() >=4 }'>
				<img src="${pList[6].hand.cardList[0].path}">
				<img src="${pList[6].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
</center></div>

<div id="Player5"><center>
Player: ${sessionScope.playservice.players[5].name}<br>
Money: ${sessionScope.playservice.players[5].money}<br>
Bet: ${sessionScope.playservice.players[5].bet}<br>

<c:choose>
    	<c:when test='${game!=null && game.getCountRounds()==6}'>
    		<c:if test='${pList[5].isHasFolded()!=true  && pList.size() >=4 }'>
				<img src="${pList[5].hand.cardList[0].path}">
				<img src="${pList[5].hand.cardList[1].path}">
			</c:if>
		</c:when>
</c:choose>
</center></div> <br> 

<%
	String playTurn= (String)request.getServletContext().getAttribute("turn");
	String gameStart= (String)request.getServletContext().getAttribute("start");
		if(gameStart==null){
			out.println("Start The Game, ");	
			out.println("the number of Players: "+al.size());
		}else{
			out.println(gameStart);
			out.println(playTurn);
		}
%>
</div>

 <div id="choices"><center><br>
	
 	<c:choose>
    	<c:when test='${pList.size() >=3 }'>
    			<c:if test='${game.isResetGame()==true || game==null}'>
				 <form action="success.do" method="get" id="startForm">
 					<input type ="submit" value="Start Game" name="startbtn"  id="startbtn" />
		 		</form>
		 		</c:if>
    	</c:when>
    	
	</c:choose>
	<c:choose>
		<c:when test='${game!=null && game.isNotOver()==false && game.isResetGame()==false}'>	
 				<form action="reset.do" method="post" id="endForm">
 					<input type ="submit" value="Reset Game" name="endbtn" id="endbtn" />
		 		</form>
    	</c:when>
	</c:choose>
	
	<form action="success.do" method="post" id= "choiceForm" onload="formhide()"> 
	Call:<input name="choose" type="radio" value="call"></input>
	Check:<input name="choose" type="radio" value="check"></input>
	Fold:<input name="choose" type="radio" value="fold"></input>
	Raise:<input name="choose" type="radio" value="raise"></input>
	<input type ="text" name="raisetxt" maxlength="2" size="2" onKeyPress="return numbersonly(this, event)"/><br>
	   <input type="submit" value="Done"/>
 	</form>
 	
</center></div>

<div id="sessionCards"><center>	
<c:choose>
    	<c:when test='${game!=null && game.isResetGame()==false}'>	
			Your Cards:<br>
		<img src="${sessionScope.player.hand.cardList[0].path}">
		<img src="${sessionScope.player.hand.cardList[1].path}">
		</c:when>
</c:choose>
</center> 

</div>
 
</body>
</html>